package ai.people.platform.archives.controller;

import ai.people.netmon.framework.domain.gang.construction.request.RelationLibConfigListRequest;
import ai.people.netmon.framework.domain.gang.construction.request.RelationLibConfigSaveOrUpdateRequest;
import ai.people.netmon.framework.domain.gang.construction.request.RelationRuleRequest;
import ai.people.netmon.framework.domain.gang.construction.valid.ValidationGroup;
import ai.people.netmon.framework.domain.gang.construction.vo.RelationLibConfigVO;
import ai.people.netmon.framework.domain.gang.construction.vo.RelationRuleVO;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.framework.model.response.Result;
import ai.people.netmon.framework.utils.ResultUtil;
import ai.people.platform.archives.service.RelationLibService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 关系库接口
 *
 * @author zhenglin
 * @date 2022/7/19
 */
@RestController
@RequestMapping("/relationLib")
public class RelationLibController {

    @Autowired
    RelationLibService relationLibService;

    /**
     * 获取规则
     *
     * @return {@link Result}<{@link List}<{@link RelationRuleVO}>>
     */
    @PostMapping("/getRelationRule")
    public Result<RelationRuleVO> getRelationRule(@Validated @RequestBody RelationRuleRequest request) {
        RelationRuleVO list = relationLibService.getRelationRule(request);
        return ResultUtil.success(list);
    }


    /**
     * 关系库-更新规则
     *
     * @param request 请求
     * @return {@link Result}<{@link Boolean}>
     */
    @PutMapping
    public Result<Boolean> updateConfig(@Validated(ValidationGroup.Update.class) @RequestBody RelationLibConfigSaveOrUpdateRequest request) {
        relationLibService.updateConfig(request);
        return ResultUtil.success();
    }

    /**
     * 关系库-删除规则
     *
     * @param id id
     * @return {@link Result}<{@link Boolean}>
     */
    @DeleteMapping("/{id}")
    public Result<Boolean> deleteConfig(@PathVariable("id") Long id) {
        relationLibService.deleteConfig(id);
        return ResultUtil.success();
    }

    /**
     * 关系库-列表
     *
     * @param request 请求
     * @return {@link Result}<{@link PageResponse}<{@link RelationLibConfigVO}>>
     */
    @PostMapping("/list")
    public Result<PageResponse<RelationLibConfigVO>> listConfig(@RequestBody RelationLibConfigListRequest request) {
        PageResponse<RelationLibConfigVO> list = relationLibService.listConfig(request);
        return ResultUtil.success(list);
    }

}
